package com.qf.index.gcrdo;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import lombok.SneakyThrows;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @Author: 葛成瑞
 * @Date: 2025/4/22 13:36
 */
public class GetNoTransRecord {
    @SneakyThrows
    public static void main(String[] args) {

        // 此程序是用于遍历unified_search_summary_0406 表只要字段 title 有值 且是英文的 但是cn_title 没有值的记录 则记录下载存储到表  unified_search_no_trans

        // 遍历unified_search_summary_0406 表
        String table = "unified_search_summary_0406";
        String saveTable = "unified_search_no_trans";
        Db use = Db.use();
        Integer maxId =use.query("select max(id) as maxid from "+table).get(0).getInt("maxid");
        System.out.println(maxId);
        Integer minId = 0;
        Integer step = 10000;
        for (int i = minId; i < maxId; i+=step) {
            System.out.println("页码："+i+" 到 "+(i+step)+" 开始查询");
            String sql = "select id,title,cn_ti from "+table+" where id > "+i+" and id <= "+(i+step)+ " AND  title is not null   ";
            List<Entity> query = use.query(sql);
            for (Entity entity : query) {
                String cnTi = entity.getStr("cn_ti");
                if (StringUtils.isEmpty(cnTi)) {
                    entity.setTableName(saveTable);
                    use.insert(entity);
                }
            }
        }

    }
}
